package com.zhao.modleclass.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhao.modleclass.R;
import com.zhao.modleclass.bean.LiveActivityBean;

public class SC_TeacherWebView extends AppCompatActivity {
    private WebView webView;
    private TextView textView_Title;
    private ImageView imageView_back,imageView_shack;
    private Context mContext;
    private LiveActivityBean liveActivityBean;
    private  int CourseId;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sc__teacher_web_view);
        //设置状态栏的颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            //获取样式中的属性值
            TypedValue typedValue = new TypedValue();
            this.getTheme().resolveAttribute(Color.parseColor("#FF4081"), typedValue, true);
            int[] attribute = new int[]{Color.parseColor("#FF4081")};
            TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);
            int color = array.getColor(0, Color.parseColor("#FF4081"));
            array.recycle();
            window.setStatusBarColor(color);
        }
        textView_Title= (TextView) findViewById(R.id.textView_webView_Title);
        imageView_back= (ImageView) findViewById(R.id.imageView_webView_back);
        imageView_shack= (ImageView) findViewById(R.id.imageView_webView_shack);
        initData();
    }

    private void initData() {
        Intent intent=getIntent();
        Bundle bundle=intent.getBundleExtra("url");
        final String url= (String) bundle.get("url");
                bundle=intent.getBundleExtra("name");
        String name= (String) bundle.get("name")+"的主页";
        textView_Title.setText(name);
        imageView_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //初始化控件
        webView= (WebView) findViewById(R.id.webView_SC_TeacherWebView);
        webView.loadUrl(url);
        //开启javaScript支持
        webView.getSettings().setJavaScriptEnabled(true);
        //强制使用控件加载网页
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(url);
                return true;
            }
        });
    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.imageView_webView_back:
                finish();
                break;
            case R.id.imageView_webView_shack:
//
                break;
        }
    }
}
